# coding=utf-8
"""
Author: Mr.夏末
@Function: 功能名称
"""
import os
import re
import time

from class11.webkeys import Web
from selenium.webdriver import ActionChains

web = Web()
web.openbrowser()
driver = web.driver

#打开12306登录页
web.get_url('https://kyfw.12306.cn/otn/resources/login.html')
web.input('//input[@id="J-userName"]','17863087593')
web.input('//input[@id="J-password"]','shuai21654')
web.click("J-login")
web.slide12306()
web.sleep(1)

# 打开电商网站登录页
web.get_url("http://47.105.110.138:8000/index.php/Home/user/login.html")
web.input('username','2529085125@qq.com')
web.input('//*[@id="password"]','123456')
<<<<<<< HEAD
web.get_verify("//img[@id='verify_code_img']")
=======
web.get_verify()
>>>>>>> bbe5575b39a883d3ba625b099ff1bdaa9564f25f
# 输入验证码
web.input('//*[@id="verify_code"]','{verify}')
# 点击登录
web.click('//a[contains(text(),"登")]')

# 获取昵称
nickname = web.get_text('//a[@class="red userinfo"]')
print(nickname)

#搜索
web.input('//*[@id="q"]','手机')
web.click('//*[@id="sourch_form"]/a')

# 点击第1个加入购物车
web.click('//a[contains(text(),"小米手机")]/../..//a[text()="加入购物车"]')
web.click('join_cart')
# 强制等待
web.sleep(1)
web.click('//*[@id="layui-layer1"]/span/a')

# 结算
web.click('//*[@id="hd-my-cart"]/a/div/span')
web.click("//a[text()='去结算']")
web.click("//button[contains(text(),'提交订单')]")

# 获取订单号
web.get_text('//p[@class="succ-p"]',r'\d{18}')
web.sleep(1)
# 点击我的订单
web.click("//a[text()='我的订单']")
web.switchwin('我的订单')

# 搜索订单号
web.input('//*[@id="search_key"]', '{text}')
web.click('//*[@id="search_order"]/input[2]')
web.sleep(2)